package test211706330;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;




public class MathExam211706330 {
	static FileOutputStream out;
	/**
	* 
	*
	* 问题
	*/
	static String[] question;
	/**
	* 
	*
	* 答案
	*/
	static String[] answer;
	static byte[] buff=new byte[] {};
	public static void main(String[] args) throws IOException {
		Scanner scnext=new Scanner(System.in);
		int number=scnext.nextInt();
		//判断是否为负数
		int number1=scnext.nextInt();
	
		//调用方法
		setquestion(number,number1);
		if(setquestion(number,number1)=="")
		{
			infomation(question,answer);
		}
		else if(setquestion(number,number1)=="输入题目数不正确")
		{
			System.out.println("输入题目数不正确");
		}
		else
		{
			System.out.println("输入年级不对");
		}
	
		scnext.close();
	}
	
	//出题 和 打印题目到文档中
	public static String setquestion(int n,int m) throws IOException
	{
		
		String message="";
		if(n<0 && m>=1 && m<=2)
		{
			message="输入题目数不正确";
			return message;
		}
		question = new String[n];
		answer = new String[n];
		final Random random=new Random();
		String symbot;
		int xnumber;
		int ynumber;
		int count=1;
		
		if(m==1)
		{
			
			String[] sign= {"+","-"};
			for(int i=0;i<n;i++)
			{
				xnumber=random.nextInt(50);
				ynumber=random.nextInt(50);
				symbot=sign[random.nextInt(2)];
				if(symbot.indexOf("+")<0)
				{
					question[i]="("+count+")"+" "+xnumber+"-"+ynumber+" "+"=";
					count++;
					answer[i]=String.valueOf(xnumber-ynumber);
				}
				else
				{
					question[i]="("+count+")"+" "+xnumber+"+"+ynumber+" "+"=";
					count++;
					answer[i]=String.valueOf(xnumber+ynumber);
				}
			}
		}
		else if(m==2)
		{
			String[] sign1= {"*","/"};
			symbot=sign1[random.nextInt(2)];
			for(int i=0;i<n;i++)
			{
				xnumber=random.nextInt(50);
				ynumber=random.nextInt(50);
				symbot=sign1[random.nextInt(2)];
				if(symbot.indexOf("*")<0)
				{
					question[i]="("+count+")"+" "+xnumber+"/"+ynumber+" "+"=";
					count++;
					if(xnumber % ynumber==0)
					{
						answer[i]=" "+String.valueOf(xnumber/ynumber);	
					
					}
					else
					{
						answer[i]=" "+String.valueOf(xnumber/ynumber)+"..."+String.valueOf(xnumber % ynumber);
					}
				
				}
				else
				{
					int x1number=random.nextInt(10);
					int x2number=random.nextInt(10);
					question[i]="("+count+")"+" "+x1number+"*"+x2number+" "+"=";
					count++;
					answer[i]=" "+String.valueOf(x1number*x2number);
				}
			}
		}
		else
		{
			message="输入的年级不对";
			return message;
		}
		return message;
	
	}
	public static void infomation(String[] question, String[] answer) throws IOException
	{
		String filename="out211706330.txt";
		File file=new File(filename);
		File dir=file.getParentFile();
		if(dir!=null && !dir.exists())
		{
			dir.mkdir();
		}
		out=new FileOutputStream(file);
		for(int i=0;i<question.length;i++)
		{
			
			buff=question[i].getBytes();
			out.write(buff,0,buff.length);
			out.write("\r\n".getBytes());
		}
		for(int i=0;i<question.length;i++)
		{
			question[i]=question[i]+answer[i];
		}
	out.write("----------------标准答案---------------------".getBytes());
	out.write("\r\n".getBytes());
	for(int i=0;i<question.length;i++)
	{
		
		buff=question[i].getBytes();
		out.write(buff,0,buff.length);
		out.write("\r\n".getBytes());
	}
	Date date=new Date();
	SimpleDateFormat dateformat=new SimpleDateFormat("yyyy年MM月dd日HH:mm");
	String time=dateformat.format(date);
	out.write("           211706330 林潇 ".getBytes());
	out.write(time.getBytes());
	out.close();
	}

	
}